const mongoose = require('mongoose')
const Image = mongoose.model('Image')
const Comment = mongoose.model('Comment')

// const funs = async (Image) => {
//     const info = await Image.aggregate().group(
//         {
//             _id: null,
//             numOfImages: {$sum: 1},
//             numOfLikes: {$sum: "$likes"},
//             numOfView: {$sum: "$viewtimes"},
//         }
//     )
//     const comTol = await Comment.countDocuments()
//     console.log(info)
//     return{
//         ...info[0]

//     }
// }

const funs = () => Promise.all([
    Image.aggregate().group(
        {
            _id: null,
            numOfImages: {$sum: 1},
            numOfLikes: {$sum: "$likes"},
            numOfView: {$sum: "$viewtimes"}
        }
    ),
    Comment.countDocuments()   
]).then(([obj1, numOfComments]) => ({
    ...obj1[0], numOfComments
}))
module.exports = funs